package leetcode_字符串._09高精度运算;

/**
 * 加一
 */
public class _66 {

    public int[] plusOne(int[] digits) {
        int carry = 0;
        for (int i = digits.length - 1; i >= 0; --i) {
            int tem = digits[i] + carry;
            if (i == digits.length - 1) {
                tem += 1;
            }
            digits[i] = tem % 10;
            carry = tem / 10;
        }
        if (digits[0] == 0) {
            int[] ints = digits;
            digits = new int[digits.length + 1];
            digits[0] = carry;
            System.arraycopy(ints, 0, digits, 1, ints.length);
        }
        return digits;
    }
}
